package com.wmm.job1;

public class JobOne {

    public static void main(String[] args) {

        String result = "";
        //1、初始化字符串
        String str = "ABCD123!@#$%ab";
        //2、编写大写字母的正则表达式
        String s1 = "[A-Z]";
        result =  show(str,s1);
        System.out.println("发现大写字母"+ result + ",目前大写字母有" + result.length() + "个");

        //3、编写小写字母正则表达式
        String s2 = "[a-z]";
        result =  show(str,s2);
        System.out.println("发现小写字母"+ result + ",目前小写字母有" + result.length() + "个");

        //4、编写数字的正则表达式
        String s3 = "[0-9]";
        result =  show(str,s3);
        System.out.println("发现数字"+ result + ",目前数字有" + result.length() + "个");

        //5、编写其他字符正则表达式
        String s4 = "[^a-zA-Z0-9]";
        result =  show(str,s4);
        System.out.println("发现其他字符"+ result + ",目前其他字符有" + result.length() + "个");
    }

    public static String show(String str,String regex){
        String ss = "";
        String ch = "";
        int num = 0;
        for(int i = 0;i<str.length();i++){
            ss = str.substring(i,i+1);
            if (ss.matches(regex)){
                ch += ss;
            }
        }
        return ch;
    }
}
